#include"Gun.h"
#include"Solider.h"

Solider::Solider(std::string name)
{
    this->_name = name;
    this->_ptr_gun = nullptr;//初始化指针指向空
}

Solider::~Solider()
{
    if(this->_ptr_gun == nullptr)
    {
        return;
    }
    delete this->_ptr_gun;
    this->_ptr_gun = nullptr;
}

void Solider::addGun(Gun * ptr_gun)
{
    this->_ptr_gun = ptr_gun;
}

void Solider::addBulletToGun(int num)
{
    if(_ptr_gun == nullptr) 
    {
        std::cout<<"没有创建枪的实例!"<<std::endl;
        return;
    }
        
    this->_ptr_gun->addBullet(num);
}

bool Solider::fire()
{
    this->_ptr_gun->shoot();//开始射击
    return true;
}

